package com.tien.utils;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

/**
 *
 * @author  Tian 
 * @Mail    tianxin_star@163.com
 * @version date：Mar 8, 2012 3:42:48 PM
 * 
 */
public class CallBackJSONUtil {
	public static void printSuccessState(Object object, HttpServletResponse response) {
		JSONObject state = new JSONObject();
		state.put("state", "S");
		if(object != null)
			state.put("data", object);
		try {
			response.getWriter().print(state);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void printErrorState(Exception e, HttpServletResponse response) {
		JSONObject state = new JSONObject();
		state.put("state", "F");
		try {
			response.getWriter().print(state);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
	
	public static void printAccessDeniedState(Exception e, HttpServletResponse response) {
		JSONObject state = new JSONObject();
		state.put("state", "T");
		try {
			response.getWriter().print(state);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
}
